<template>
  <wd-toast></wd-toast>
  <wd-notify/>
  <wd-message-box/>
  <view >
    <!--    <tyz-navbar>-->
    <!--    </tyz-navbar>-->
    <wd-button class="ml-20rpx m-20rpx" @click="addTo">随机新增一条</wd-button>
    <wd-button class="ml-20rpx m-20rpx" @click="goToOrc">去ORC</wd-button>
      <wd-card :title="item.username" v-for="item in userList" :key="item._id">
        <wd-transition :show="true" name="fade-up">
          {{ item.nickname }}

        </wd-transition>
        <template #footer>
          <wd-button size="small" type="error" plain @click="del(item._id)">删除</wd-button>
        </template>
      </wd-card>
  </view>
</template>

<script lang="ts" setup>
import {onReachBottom} from '@dcloudio/uni-app'
import {ref, reactive, nextTick, onMounted} from 'vue'
import {useNotify, useToast, useMessage} from 'wot-design-uni'
import {debounce} from 'lodash'
import useCommonFn from '@/hooks/useCommonFn';

const {showMask, openSift} = useCommonFn() as any
const message = useMessage()
const message1 = useMessage('wd-message-box-slot')
const {
  show: showToast,
  success: successToast,
  warning: warningToast,
  loading: showLoading,
  close: hideLoading
} = useToast()
const {userInfo} = storeToRefs(useAuthStore()) // 解构pinia的store
const userList = ref([])
const router = useRouter()
const nameArr = ref([
    "长得帅",
    "长得丑",
    "长得一般",
    "长得好看",
    "长得不好看",
])
const nickNameArr = ref([
    "小刘同学",
    "小王同学",
    "小张同学",
    "小陈同学",
    "小赵同学",
      "张师傅",
      "李师傅",
      "王师傅",
      "刘师傅",
      "陈师傅",
      "赵师傅",
      "孙师傅",
])
const goToOrc = () =>{
  router.push({name:'Change'})
}
const addTo = () => {
  uniCloud.callFunction({
    name: 'template-user',
    data: {
      username: nickNameArr.value[Math.floor(Math.random() * nickNameArr.value.length)],
      password: "123456",
      //五个钟随机取一个
      nickname: nameArr.value[Math.floor(Math.random() * nameArr.value.length)]  ,
      gender: 1,
      status: 1,
      mobile: "18888888888",
      mobile_confirmed: 0,
      avatar: "https://www.uviewui.com/common/logo.png",
      register_date: new Date().getTime(),
      token: new Date().getTime() + "dad21323cadad13fdfas"
    }
  }).then((res) => {
    console.log(res)
    console.log(res.result)
    getUserList()
    successToast(res.result.msg)
  }).catch((err) => {
    console.log(err)
  })
}
const getUserList = () =>{
  uniCloud.callFunction({
    name: 'getUserList',
  }).then((res) => {
    console.log(res)
    console.log(res.result.data.data)
    userList.value = res.result.data.data
  }).catch((err) => {
    console.log(err)
  })
}
const del = (id) => {
  message
      .confirm({
        msg: '确定要删除吗',
        title: '提示'
      })
      .then(() => {
        showLoading({ loadingType: 'ring', msg: '删除中' })
        uniCloud.callFunction({
          name:'delUser',
          data:{
            id:id
          }
        }).then((res) => {
          console.log(res)
          console.log(res.result)
          setTimeout(()=>{
            getUserList()
            hideLoading()
          },2500)
        }).catch((err) => {
          console.log(err)
        })
      })
      .catch(() => {
        console.log('点击了取消按钮')
      })

}
onLoad(() => {
  getUserList()
})
onShow(() => {

})
onMounted(() => {

})
// 触底加载
onReachBottom(() => {

})
</script>
<style lang="scss" scoped>
@import '@/static/css/home.scss';

::v-deep .wd-button .is-primary {
  background: #000 !important;
}

.reservation-info {
  view {
    width: 33%;
  }
}
</style>